<template>
	<!-- 装配过账 -->
	<div>
		<v-card class="align-left">
			<v-card-title>
				<v-row>
					<!-- 扫码组件 -->
					<barcodescan  postbillNme="postbill_assembly" @handle="handleBarcode"></barcodescan>
					<!-- {{value}} -->
					<v-text-field width="20" v-model="tempProcessCardCode" ref="qrCodeInput" dense outlined
						label="输入流程卡号">
					</v-text-field>
					<v-btn class="ml-2" depressed color="primary" @click="postBill()">
						扫码过账
					</v-btn>
					<v-col cols="12">
						<v-btn class="ml-2" depressed color="primary" @click="bindAreaDialog=true">绑定工作中心</v-btn>
						<v-btn class="ml-2" depressed color="primary" :disabled="workCenterModel==null"
							@click="bindOperationUserDialog=true,loadUser()">绑定人员</v-btn>
						<!-- 		<v-btn class="ml-2" depressed color="primary" :disabled="workCenterModel==null"
							@click="getWorkCenterProcessCards">刷新绑定的流程卡</v-btn> -->
					</v-col>
					<v-col cols="12" sm="3">
						<v-text-field width="20" v-model="queryWorkCenter.childrenCode" label="工单号" dense outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12" sm="2" md="2">
						<v-btn depressed color="primary" @click="serach">查询</v-btn>
						<v-btn class="ml-3" depressed color="primary" @click="getWorkCenterProcessCards">
							刷新</v-btn>
					</v-col>
				</v-row>

				<v-spacer></v-spacer>

				<v-spacer></v-spacer>
				<div v-if="workCenterModel!=null">

					<v-chip class="ma-2" color="cyan" label text-color="white">
						<v-icon left>
							mdi-label
						</v-icon>
						区域：{{workCenterModel.station.areatypename}}
					</v-chip>
					<!-- 					<v-chip class="ma-2" color="cyan" label text-color="white">
						<v-icon left>
							mdi-label
						</v-icon>
						工位：{{workCenterModel.station.name}}
					</v-chip> -->
					<br />
					<v-chip class="ma-2" color="primary" label text-color="white">
						<v-icon left>
							mdi-account-circle-outline
						</v-icon>
						人员：{{workCenterModel.operationusername}}
					</v-chip>
				</div>
			</v-card-title>
			<v-card-text>
				<v-row dense>
					<v-col cols="6">
						<v-alert border="left" text color="blue-grey">
							<p class="text-center">工单信息</p>
							<p class="text-center" v-if="currentClickSingleProcessCardModel!=null">
								<a
									class="ml-5">母工单:{{ currentClickSingleProcessCardModel.childrenOrder.masterWorkOrder.workcode}}</a>
								<a
									class="ml-5">交期:{{ currentClickSingleProcessCardModel.childrenOrder.deliverydate}}</a>
								<a class="ml-5">总数量:{{currentClickSingleProcessCardModel.childrenOrder.totalcount}}</a>
								<a class="ml-5">工单类型:{{currentClickSingleProcessCardModel.childrenOrder.typename}}</a>
							</p>
						</v-alert>
						<v-card>
							<v-card-title>
								<v-alert width="100%" style="height: 60px;;caret-color: rgb(103, 194, 58);" text
									color="rgb(144 153 255)">
									<p class="text-center">选中流程卡明细</p>
								</v-alert>
							</v-card-title>
							<v-card-text>
								<v-data-table small fixed-header dense :headers="
								[
									{text: '总数量',
									 value: 'totalcount',
									 align:'center'
									},
									{text: '等待数量',
									 value: 'waitcount',
									 align:'center'
									},
									{text: '完成数量',
									 value: 'complatecount',
									 align:'center'
									},
									{text: '完成比例',
									 value: 'complateproportion',
									 align:'center'
									},
									{text: '状态',
									 value: 'statusname',
									 align:'center'
									}
								]
								" :items="upPorcessCardList" item-key="code" hide-default-footer class="text-no-wrap elevation-1" show-expand
									single-expand @item-expanded="expandedSingleProcessCardEvent">
									过账明细
									<template v-slot:expanded-item="{ headers, item }">
										<td :colspan="headers.length">
											<v-data-table small fixed-header dense
												:headers="processCardpostbillHeaderList"
												:items="item.processCardpostbillList" item-key="id" class="text-no-wrap"
												hide-default-footer>
											</v-data-table>
										</td>
									</template>
								</v-data-table>
							</v-card-text>
						</v-card>

						<v-card class="mt-2">
							<v-card-title>
								<v-alert width="100%" style="height: 60px;;caret-color: rgb(103, 194, 58);" text
									color="rgb(144 153 255)">
									<p class="text-center">待完成明细</p>
								</v-alert>
							</v-card-title>
							<v-card-text>
								<v-data-table small dense fixed-header :headers="[
									{text: '操作',
									 value: 'actions',
									 align:'center'
									},
									{text: '工单号',
									 value: 'childrenOrder.code',
									 align:'center'
									},
									{text: '名称',
						       value: 'childrenOrder.name',
						       align:'center'
									},
									{text: '开始时间',
						       value: 'starttime',
						       align:'center'}
									]" :items="processCardList" item-key="id" class="text-no-wrap" show-select :single-select="true"
									:loading="processCardLoading" :options.sync="processCardOptions"
									:server-items-length="processCardTotalCount" :footer-props="vuetifyDefaultPage"
									@item-selected="processCardSelectSingleEvent">
									<template v-slot:item.actions="{ item }">
										<div>
											<v-btn class="ml-2" small tile color="primary"
												@click="openExceptionDialog(item)">
												录入异常信息
											</v-btn>
											<v-btn small class="ml-2" tile color="primary"
												@click="currentClickSingleProcessCardModel=item,loadWaitCreateMaterialDataList()">
												退料单
											</v-btn>
											<!-- <v-btn v-if="item.childrenOrder.status==51||item.childrenOrder.status==60"
												small class="ml-2" tile color="primary"
												@click="openOutsourcingDetailDialog(item)">
												装配终检
											</v-btn> -->
											<v-tooltip top>
												<template v-slot:activator=" { on, attrs }">
													<v-btn small class="ml-2" tile color="primary" v-bind="attrs"
														v-on="on" :disabled="
														item.childrenOrder.status==50||
														item.childrenOrder.status==60||
														item.childrenOrder.status==51||
														item.childrenOrder.status==58||
														item.childrenOrder.status==59||(item.childrenOrder.totalcount -item.resultcount)==0"
														@click="currentClickSingleProcessCardModel=item,SplitBatchDialog=true">
														拆批
													</v-btn>
												</template>
												<span>状态为过账中的流程卡不能拆批</span>
											</v-tooltip>
											<!-- <v-btn v-if="item.childrenOrder.status!=51" small class="ml-2" tile
												color="primary"
												@click="currentClickSingleProcessCardModel=item,wOuntDialog=true">
												委外
											</v-btn> -->
										</div>
										<!-- 	<v-btn small class="ml-2" tile color="primary" @click="postBill(item.code)">
																							扫码过账
																						</v-btn> -->
										<!-- 			<v-btn small class="ml-2" tile color="primary"
																							@click="operationStartOrStopOrEnd(item,50)">
																							开始
																						</v-btn>
																						<v-btn small class="ml-2" tile color="primary"
																							@click="operationStartOrStopOrEnd(item,10)">
																							暂停
																						</v-btn>
																						<v-btn small class="ml-2" tile color="primary"
																							@click="operationStartOrStopOrEnd(item,60)">
																							结束
																						</v-btn>
											-->
									</template>
								</v-data-table>
							</v-card-text>
						</v-card>
					</v-col>
					<v-col cols="6">
						<v-alert text color="blue-grey" border="left">
							<p class="text-center">加工信息</p>
							<p class="text-center" v-if="currentClickSingleProcessCardModel!=null">
								<a class="ml-5">完成工单:{{this.currentClickSingleProcessCardModel.resultcount}}</a>
								<a class="ml-5">产出工时:{{this.currentClickSingleProcessCardModel.workhours}}</a>
							</p>
						</v-alert>
						<v-card v-if="currentClickSingleProcessCardModel!=null">
							<v-card-title>
								<v-alert width="100%" style="height: 60px;;caret-color: rgb(103, 194, 58);" text
									color="rgb(144 153 255)">
									<p class="text-center">
										<a v-if="currentClickSingleProcessCardModel.childrenOrder!=null"
											style="float: left;"
											:href="currentClickSingleProcessCardModel.childrenOrder.picurl"
											target="_Blank">查看大图</a>
										图纸：{{currentClickSingleProcessCardModel.childrenOrder.piccode}}
									</p>
								</v-alert>
							</v-card-title>
							<v-card-text>
								<pdf ref="pdf" :src="currentClickSingleProcessCardModel.childrenOrder.picurl">
								</pdf>
							</v-card-text>
						</v-card>
					</v-col>
				</v-row>
			</v-card-text>
		</v-card>

		<!-- 选择工作中心对话框 -->
		<v-dialog v-model="loadWorkCenterDialog" max-width="1000px">
			<v-card>
				<v-card-title>
					选择工作中心
				</v-card-title>
				<v-card-text>
					<v-data-table small fixed-header dense :headers="[
						{text: '区域',
						 value: 'station.areatypename',
						 align:'center'
						},
						{text: '工位',
						 value: 'station.name',
						 align:'center'
						},
						{text: '绑定人员',
						 value: 'operationusername',
						 align:'center'
						}]" :items="workCenterList" item-key="id" class="text-no-wrap elevation-1" show-select :single-select="true"
						@item-selected="workCenterSelectEvent">
					</v-data-table>
				</v-card-text>
				<v-card-actions>
					<v-spacer></v-spacer>
					<v-btn color="primary" text depressed @click="loadWorkCenterDialog=false">关闭</v-btn>
				</v-card-actions>
			</v-card>
		</v-dialog>
		<!-- 绑定区域对话框 -->
		<v-dialog v-model="bindAreaDialog" max-width="400px">
			<v-card>
				<v-card-title>
					<span class="text-h5">绑定工作中心</span>
				</v-card-title>
				<v-card-text>
					<v-select v-model="stationModel.areatype" :items="areaProductionEnumList" label="选择工作中心" dense
						outlined @input="areaSelectEvent"></v-select>
					<!-- <v-select v-model="stationModel.id" :items="tempstationList" label="选择工位" dense outlined> -->
					</v-select>
				</v-card-text>
				<v-card-actions>
					<v-spacer></v-spacer>
					<v-btn color="blue darken-1" text @click="bingAreaSubmit">
						确定
					</v-btn>
					<v-btn color="blue darken-1" text @click="cancel">
						取消
					</v-btn>
				</v-card-actions>
			</v-card>
		</v-dialog>

		<!-- 绑定人员对话框 -->
		<v-dialog v-model="bindOperationUserDialog" max-width="500px">
			<v-card>
				<v-card-title>
					<span class="text-h5">绑定人员</span>
				</v-card-title>
				<v-card-text>
					<v-card class="overflow-y-auto" max-height="400" max-width="500">
						<v-card-title>
							<v-text-field fiexd v-model="bindOperationUserSearchInput" append-icon="mdi-magnify"
								label="输入工号或姓名或登录账号,按回车" single-line hide-details autocomplete
								@keypress.enter="loadUser">
							</v-text-field>
						</v-card-title>
						<v-list two-line>
							<v-list-item-group v-model="bindOperationUserSelects" active-class="green--text" multiple>
								<template v-for="(item, index) in userList">
									<v-list-item :key="item.id+'only'">
										<template v-slot:default="{ active }">
											<v-list-item-content>
												<v-list-item-title v-text="item.code" style="font-weight:bold;">
												</v-list-item-title>

												<v-list-item-subtitle class="mt-2">姓名：{{item.realname}}
												</v-list-item-subtitle>
												<v-list-item-subtitle class="mt-2">账号：{{item.name}}
												</v-list-item-subtitle>
											</v-list-item-content>

											<v-list-item-action>
												<!-- <v-list-item-action-text v-text="item.action"></v-list-item-action-text> -->

												<v-icon v-if="!active" color="grey lighten-1">
													mdi-star-outline
												</v-icon>

												<v-icon v-else color="yellow darken-3">
													mdi-star
												</v-icon>
											</v-list-item-action>
										</template>
									</v-list-item>

									<v-divider v-if="index < userList.length - 1" :key="index"></v-divider>
								</template>
							</v-list-item-group>
						</v-list>
					</v-card>
				</v-card-text>
				<v-card-actions>
					<v-spacer></v-spacer>
					<v-btn color="blue darken-1" text @click="bindOperationUsersSubmit">
						确定
					</v-btn>
					<v-btn color="blue darken-1" text @click="cancel">
						取消
					</v-btn>
				</v-card-actions>
			</v-card>
		</v-dialog>

		<!-- 拆批对话框 -->
		<v-dialog v-model="SplitBatchDialog" max-width="500px" v-if="this.currentClickSingleProcessCardModel!=null">
			<v-card>
				<v-card-title>
					拆批
				</v-card-title>

				<v-form ref="form">
					<v-card-text>
						<v-alert class="text-left" type="warning" dark>
							拆批数量必须大于0!
						</v-alert>
						<p class="mb-3">
							<a>可拆批数量:{{currentClickSingleProcessCardModel.childrenOrder.totalcount -this.currentClickSingleProcessCardModel.resultcount}}</a>
						</p>
						<br />
						<v-text-field label="输入拆批数量" outlined v-model="dialogSplitBatchCount" :rules="qtyRule">
						</v-text-field>
					</v-card-text>
					<v-card-actions>
						<v-spacer></v-spacer>
						<v-btn color="primary" text
							:disabled="dialogSplitBatchCount>this.currentClickSingleProcessCardModel.resultcount||dialogSplitBatchCount==0"
							@click="intoProduction">
							确定
						</v-btn>
						<v-btn color="primary" text @click="cancel">
							关闭
						</v-btn>
					</v-card-actions>
				</v-form>
			</v-card>
		</v-dialog>
		<!-- 委外对话框 -->
		<v-dialog v-model="wOuntDialog" persistent max-width="290" v-if="currentClickSingleProcessCardModel!=null">
			<v-card>
				<v-card-title class="text-h5">
					委外
				</v-card-title>
				<v-card-text>
					为此工单:<a
						style="font-weight:bold;">{{ currentClickSingleProcessCardModel.childrenOrder.code}}</a>委外？请输入委外数量，默认完工数量。
					<v-text-field class="mt-4" outlined label="委外数量" :rules="qtyRule"
						v-model="currentClickSingleProcessCardModel.resultcount"></v-text-field>
					<v-textarea outlined name="input-7-4" label="备注"
						v-model="currentClickSingleProcessCardModel.description2"
						:value="currentClickSingleProcessCardModel.description2">
					</v-textarea>
				</v-card-text>
				<v-card-actions>
					<v-spacer></v-spacer>
					<v-btn color="green darken-1" text @click="wOuntSubmit">
						确定
					</v-btn>
					<v-btn color="green darken-1" text @click="cancel">
						取消
					</v-btn>
				</v-card-actions>
			</v-card>
		</v-dialog>
		<!-- 退料对话框 -->
		<v-dialog v-model="backMaterialDialog" persistent max-width="900">
			<v-stepper v-model="backMaterialEL">
				<v-stepper-header>
					<v-stepper-step :complete="backMaterialEL > 1" step="1">
						选择退料类型
					</v-stepper-step>

					<v-divider></v-divider>

					<v-stepper-step step="2">
						选择物料（退料单）
					</v-stepper-step>
				</v-stepper-header>

				<v-stepper-items>
					<!-- 退料类型 -->
					<v-stepper-content step="1">
						<v-container class="text-subtitle-1 d-flex ">
							<v-select v-model="selectBackMaterialType" :items="BackMaterialTypeList" label="选择退料类型"
								dense outlined></v-select>
							<v-spacer></v-spacer>
							<v-btn class="ml-3" color="success" :disabled="selectBackMaterialType==0"
								@click="backMaterialEL = 2">
								下一步
							</v-btn>
							<v-btn class="ml-3" depressed @click="cancel">
								关闭
							</v-btn>
						</v-container>
					</v-stepper-content>
					<!-- 物料 -->
					<v-stepper-content step="2">
						<v-card>
							<v-card-title class="text-h5">
								编辑退料信息
							</v-card-title>
							<v-card-text>
								<v-data-table dense :headers="MaterialRequestOrderHeader"
									:items="WaitCreateMaterialDataList" :footer-props="vuetifyDefaultPage"
									item-key="materialcode" class="text-no-wrap mt-2" fixed-header>
									<template v-slot:item.check="{item }">
										<v-checkbox v-model="item.check" style="height:20px;" class="mb-5"></v-checkbox>
									</template>
									<template v-slot:item.needqty="props">
										<v-edit-dialog large save-text="保存" cancel-text="取消">
											<a>
												{{ props.item.needqty}}
											</a>
											<v-icon small class="mr-2" color="red">
												mdi-pencil
											</v-icon>
											<template v-slot:input>
												<div class="mt-4 text-h6">
													退料
												</div>
												<v-text-field label="录入退料数量" :rules="qtyRule"
													v-model="props.item.needqty"></v-text-field>
											</template>
										</v-edit-dialog>
									</template>
									<!-- 描述编辑 -->
									<template v-slot:item.description="props">
										<v-edit-dialog large save-text="保存" cancel-text="取消">
											<a>
												{{ props.item.description}}
											</a>
											<v-icon small class="mr-2" color="red">
												mdi-pencil
											</v-icon>
											<template v-slot:input>
												<div class="mt-4 text-h6">
													编辑备注
												</div>
												<v-textarea outlined name="input-7-4" label="备注"
													v-model="props.item.description" :value="props.item.description">
												</v-textarea>
											</template>
										</v-edit-dialog>
									</template>
								</v-data-table>

							</v-card-text>
							<v-card-actions>
								<v-spacer></v-spacer>
								<v-btn color="primary" text @click="backMaterialEL = 1">
									上一步
								</v-btn>
								<v-btn color="green darken-1" text @click="backMaterialSubmit">
									确定
								</v-btn>
								<v-btn color="green darken-1" text @click="cancel">
									取消
								</v-btn>
							</v-card-actions>
						</v-card>


					</v-stepper-content>
				</v-stepper-items>
			</v-stepper>
		</v-dialog>

		<!-- 过账对话框 -->
		<v-dialog v-model="postingDialog" max-width="500px" v-if="currentClickSingleProcessCardModel!=null">
			<v-card>
				<v-card-title>
					<span class="text-h5">录入完工数量</span>
				</v-card-title>
				<v-card-text>
					<v-text-field v-model="currentClickSingleProcessCardModel.tempOverCount" :rules="qtyRule"
						label="完工数量" dense outlined>
					</v-text-field>
					<v-checkbox v-model="currentClickSingleProcessCardModel.isOver" label="是否完工"></v-checkbox>
				</v-card-text>
				<v-card-actions>
					<v-spacer></v-spacer>
					<v-btn color="blue darken-1" text @click="postingSubmit">
						确定
					</v-btn>
					<v-btn color="blue darken-1" text @click="cancel">
						取消
					</v-btn>
				</v-card-actions>
			</v-card>
		</v-dialog>
		<!-- 过账 -->
		<postbillpda :postbillModel="postbillModel" :callBackLoadProcessCards="callBackLoadProcessCards"></postbillpda>
		<!-- 异常信息对话框 -->
		<andonoperation :activeAndonDialogModel="activeAndonDialogModel"></andonoperation>
		<!-- 检验对话框 -->
		<assemblycheckedit :checkInfo="checkInfo" :callBackLoadProcessCards="callBackLoadProcessCards">
		</assemblycheckedit>
	</div>
</template>

<script>
	import postbillpda from '../components/postbill_assembly_manufacturing/postbill.vue'
	import andonoperation from '../components/andon/andon_add.vue'
	import assemblycheckedit from '../components/assembly_check/assembly_check_edit.vue'
	import Barcodescan from '../components/Barcodescan.vue'
	import {
		mapActions
	} from 'vuex'
	import pdf from 'vue-pdf'

	export default {
		components: {
			pdf,
			postbillpda,
			andonoperation,
			assemblycheckedit,
			Barcodescan
		},
		name: 'mes_production_postbill_manufacturing',
		data: () => ({
			value: undefined,
			tempProcessCardCode: '',
			//检验信息
			checkInfo: {
				assemblyCheckEditDialog: false,
				cardModel: {},
			},
			//调用弹出框
			postbillModel: {
				showThisFlag: false,
				workCenterId: 0,
				//绑定的区域
				areaType: 0,
				controllerName: '',
				processCardCode: '',
			},

			queryWorkCenter: {
				childrenCode: ''
			},
			workCenterList: [],
			//工作中心对话框
			loadWorkCenterDialog: false,
			//过账明细对话框
			postingDetailDialogVisable: false,
			pramterEnums: ['AreaType', 'WorkOrderChildrenStatus', 'BackMaterialType'],
			areaEnumsValue: [4, 5, 6],
			//当前工作中心信息
			workCenterModel: null,
			stationModel: {},
			areaProductionEnumList: [],
			//所有工位信息
			stationList: [],
			tempstationList: [],
			childrenStatusEnumList: [],
			processCardQueryModel: {
				projectCode: '',
				projectName: '',
				equipmentName: '',
				childrenCode: '',
				childrenStatus: null,
			},
			processCardList: [],
			//选择的流程卡
			currentClickSingleProcessCardModel: null,
			upPorcessCardList: [],
			workingCount: 0,
			stopCount: 0,
			notStartCount: 0,
			//待检待入库
			waitCheckWaitInStorgeCount: 0,
			//委外中
			wOutCount: 0,
			processCardLoading: true,
			processCardTotalCount: 0,
			processCardOptions: {
				//页数
				page: 1,
				//每页行数
				itemsPerPage: 10
			},
			processCardDetailHeaderList: [{
				text: '开始',
				value: 'starttime'
			}, {
				text: '结束',
				value: 'endtime'
			}, {
				text: '完工数量',
				value: 'resultcount'
			}, {
				text: '工时',
				value: 'workhours'
			}],
			qtyRule: [
				v => /^[0-9]*$/.test(v) || '请输入合法数字',
				v => v >= 0 || '需求量不能小于0'
			],
			processCardDetailDataList: [],
			//流程明细扩展面板的标记值
			processCardDetailExpansionFlag: false,
			//工艺信息扩展面板的标记值
			gYExpansionFlag: false,
			gYHeaderList: [],

			//手动过账对话框
			wOuntDialog: false,
			//拆批对话框
			SplitBatchDialog: false,
			//拆批数量
			dialogSplitBatchCount: 0,
			//绑定操作人员对话框
			bindOperationUserDialog: false,
			//委外时设置流程卡的状态  0：未完工 1：已完工
			processCardStatus: -1,
			userList: [],
			//绑定区域对话框
			bindAreaDialog: true,
			//退料对话框
			backMaterialDialog: false,

			bindOperationUserSelects: [],
			bindOperationUserSearchInput: '',
			//流程卡操控明细 开始-暂停-结束
			processCardpostbillHeaderList: [],
			//报工对话框
			postingDialog: false,
			workHourSubmitIsDisable: true,
			//报工明细
			processCardDWorkHourHeaderList: [],
			//物料明细
			processCardMaterialHeaderList: [],
			//退料单相关
			BackMaterialTypeList: [],
			selectBackMaterialType: 0,
			backMaterialEL: 1,
			vuetifyDefaultPage: {
				'items-per-page-text': '每页个数',
				'items-per-page-options': [10, 20, 50, 100]
				// 'items-per-page-all-text': '100'
			},
			materialDataList: [],
			rightMaterialSearch: '',
			tabOneTotalCount: 0,
			tabOneOptions: {
				//页数
				page: 1,
				//每页行数
				itemsPerPage: 10
			},
			//退料信息
			MaterialRequestOrderHeader: [],
			WaitCreateMaterialDataList: [],
			MaterialOtherInfo: {},
			activeAndonDialogModel: {
				andonOperationDialog: false,
				childrenid: 0,
				controllerName: ''
			},
		}),

		created() {
			// this.$nextTick(() => {
			// 	this.$refs.qrCodeInput.focus()
			// })
			this.loadEnumList()
			this.LoadWorkCenterStationList()
			// this.loadProcessCardList()
			// this.loadGYHeaderList()
			this.loadMaterialHeaderList()
		},


		watch: {
			tabOneOptions: {
				handler() {
					this.loadmaterialDataList()
				},
				deep: true
			},
			processCardOptions: {
				handler() {
					this.getWorkCenterProcessCards()
				},
				deep: true
			},
		},
		methods: {

			async serach() {
				this.processCardLoading = true
				var response = await this.$httpRequest({
					url: `MES/MESPostingSC/QueryWorkCenterContent?
					workCenterId=${this.workCenterModel.id}&
					childrenCode=${this.queryWorkCenter.childrenCode}&
					pageNum=1&
					pageSize=${this.processCardOptions.itemsPerPage}
					`,
					method: 'get',
				})
				if (response.status == 1) {
					this.processCardList = response.data.data.result
					this.processCardTotalCount = response.data.data.pagination.totalRecords
					this.processCardLoading = false
				}
			},
			refreshApps() {
				this.queryWorkCenter.childrenCode = ''
				this.serach()
			},
			areaSelectEvent(item) {
				this.tempstationList = this.stationList.filter(r => r.areatype == item)
			},
			//加载所有工位信息
			async LoadWorkCenterStationList() {
				var response = await this.$httpRequest({
					url: `MES/MESPostingZP/LoadWorkCenterStationList`,
					method: 'get',
				})

				if (response.status == 1) {
					this.stationList = response.data
					this.tempstationList = this.stationList
				}
			},
			loadEnumList() {
				var that = this
				this.$httpRequest({
					url: `MES/MESCommon/GetTypes`,
					method: 'post',
					data: this.pramterEnums
				}).then(function(response) {
					if (response.status == 1) {
						that.areaProductionEnumList = response.data.filter(r => r.enumName == that.pramterEnums[
							0] && that.areaEnumsValue.indexOf(r.value) > -1)
						// areaEnumsValue
						that.childrenStatusEnumList = response.data.filter(r => r.enumName == that.pramterEnums[1])

						that.BackMaterialTypeList = response.data.filter(r => r.enumName == that.pramterEnums[2])
					} else {
						that.$message.error('加载配置信息失败')
					}
				})
			},
			//取消
			cancel() {
				// this.currentClickSingleProcessCardModel = {}
				this.bindAreaDialog = false
				this.bindOperationUserDialog = false
				this.postingDialog = false
				this.SplitBatchDialog = false
				this.wOuntDialog = false
				this.processCardStatus = -1
				this.backMaterialDialog = false
				this.selectBackMaterialType = 0
				this.backMaterialEL = 1

			},
			//绑定区域-提交
			async bingAreaSubmit() {
				if (this.stationModel.areatype == null || this.stationModel.areatype == 'undefined') {
					this.$message.warning('请先绑定工作中心！')
					return
				}
				this.currentClickSingleProcessCardModel = null
				this.upPorcessCardList = []
				//选择区域后，默认选择工位的第一项
				this.stationModel.id = this.stationList.filter(r => r.areatype == this.stationModel.areatype)[0].value
				var response = await this.$httpRequest({
					url: `MES/MESPostingZP/WorkCenterBindArea?stationid=${this.stationModel.id}`,
					method: 'get'
				})
				if (response.status == 1) {
					this.workCenterModel = response.data
					this.$message.success(response.info)
					this.bindAreaDialog = false
					this.getWorkCenterProcessCards()
				} else {
					this.$message.error(response.info)
				}
			},

			//加载用户信息
			async loadUser() {
				//TODO  departmentId ???
				var departmentId = 0
				var response = await this.$httpRequest({
					url: `MES/MESPostingZP/QueryUserList?
				  departmentId=${departmentId}&
					realnameOrcodeOrName=${this.bindOperationUserSearchInput}`,
					method: 'get'
				})
				if (response.status == 1) {
					this.userList = response.data

				}

			},

			//加载机加物料信息  type: 1：机加领料单 2：机加调拨单
			loadWaitCreateMaterialDataList() {
				var that = this
				this.$httpRequest({
					url: `MES/MESPostingZP/GetBackMaterialShowList?
					childrenid=${this.currentClickSingleProcessCardModel.childrenOrder.id}
					`,
					method: 'get'
				}).then((response) => {
					if (response.status == 1) {
						that.WaitCreateMaterialDataList = response.data.data
						that.MaterialOtherInfo.now = response.data.now
						that.MaterialOtherInfo.departname = response.data.departname
						that.MaterialOtherInfo.bigRequestCode = response.data.bigRequestCode
						that.MaterialOtherInfo.applyusername = response.data.applyusername
						that.backMaterialDialog = true
					} else {
						that.$message.error(response.info)
					}
				})

			},
			//绑定操作人员
			async bindOperationUsersSubmit() {
				if (this.bindOperationUserSelects.length <= 0) {
					this.$message.warning('请选择操作人员!')
					return
				}
				var operationuserid = this.workCenterModel.operationuserid
				var operationusername = this.workCenterModel.operationusername
				this.workCenterModel.operationuserid = ''
				this.workCenterModel.operationusername = ''
				this.bindOperationUserSelects.forEach(r => {
					var every = this.userList.filter(function(elem, index, arr) {
						if (r == index)
							return elem
					})
					if (every != null && every.length > 0) {
						this.workCenterModel.operationuserid += every[0].id + '、'
						this.workCenterModel.operationusername += every[0].realname + '、'
					}
				})

				this.workCenterModel.operationuserid = this.workCenterModel
					.operationuserid.slice(0, this.workCenterModel.operationuserid
						.length - 1)
				this.workCenterModel.operationusername = this.workCenterModel
					.operationusername.slice(0, this.workCenterModel.operationusername
						.length - 1)

				var response = await this.$httpRequest({
					url: `MES/MESPostingZP/WorkCenterBindOperationUsers?
					centerid=${this.workCenterModel.id}&
					operationuserids=${this.workCenterModel.operationuserid}&
					operationusernames=${this.workCenterModel.operationusername}&
					`,
					method: 'get',
				})
				if (response.status == 1) {
					this.workCenterModel = response.data
					this.$message.success(response.info)
					this.bindOperationUserDialog = false
					// this.getWorkCenterProcessCards()
					// this.loadProcessCardList()
				} else {
					this.workCenterModel.operationuserid = operationuserid
					this.workCenterModel.operationusername = operationusername
					this.$message.error(response.info)
				}

			},
			//加载所有工作中心
			async LoadWorkCenterList() {
				this.loadWorkCenterDialog = true
				var that = this
				var response = await this.$httpRequest({
					url: `MES/MESPostingZP/LoadWorkCenterList`,
					method: 'get',
				})
				if (response.status == 1) {
					that.workCenterList = response.data
				}
			},
			async workCenterSelectEvent(item) {
				if (item.value) {
					this.workCenterModel = item.item
					await this.getWorkCenterProcessCards()
				}
			},
			//刷新绑定的流程卡信息
			async getWorkCenterProcessCards() {
				if (this.workCenterModel == null)
					return

				this.processCardLoading = true
				var response = await this.$httpRequest({
					url: `MES/MESPostingZP/GetWorkCenterProcessCards?
					masterType=3&
					workCenterId=${this.workCenterModel.id}&	
					pageNum=${this.processCardOptions.page}&
					pageSize=${this.processCardOptions.itemsPerPage}
					`,
					method: 'get',
				})
				if (response.status == 1) {
					this.processCardList = response.data.data.result
					this.processCardTotalCount = response.data.data.pagination.totalRecords
					this.processCardLoading = false
				}
			},
			//加载流程卡
			async loadSingleProcessCard() {
				this.upPorcessCardList = []
				if (this.currentClickSingleProcessCardModel == null) {
					return
				}
				var response = await this.$httpRequest({
					url: `MES/MESPostingZP/GetProcessCard?cardId=${this.currentClickSingleProcessCardModel.id}`,
					method: 'get',
				})
				if (response.status == 1) {
					this.currentClickSingleProcessCardModel = response.data
					this.upPorcessCardList.push({
						id: this.currentClickSingleProcessCardModel.id,
						totalcount: this.currentClickSingleProcessCardModel.childrenOrder.totalcount,
						statusname: this.currentClickSingleProcessCardModel.childrenOrder.statusname,
						complatecount: this.currentClickSingleProcessCardModel.resultcount,
						waitcount: this.currentClickSingleProcessCardModel.childrenOrder.totalcount - this
							.currentClickSingleProcessCardModel.resultcount,
						complateproportion: Math.ceil((this.currentClickSingleProcessCardModel.resultcount /
							this
							.currentClickSingleProcessCardModel.childrenOrder.totalcount * 100)) + '%'
					})
				}
			},
			//下方的流程卡选中事件
			async processCardSelectSingleEvent(item) {
				if (item.value) {
					this.currentClickSingleProcessCardModel = item.item
					await this.loadSingleProcessCard()
				}
			},
			// 拆批
			intoProduction() {
				const checkChildrenIds = [this.currentClickSingleProcessCardModel.childrenOrder.id]
				if (checkChildrenIds.length <= 0) {
					this.$message.error('请选中流程卡')
					return
				}

				if (!this.$refs.form.validate())
					return

				//流程卡页面拆批之前要先确定工单状态如果是过账中不允许拆批 TODO

				var that = this
				this.$httpRequest({
					url: `MES/MESPostingZP/OrderInProduction`,
					method: 'post',
					data: {
						childrenIds: checkChildrenIds,
						splitBatchCount: this.dialogSplitBatchCount
					}
				}).then(function(response) {
					if (response.status == 1) {
						that.SplitBatchDialog = false
						that.getWorkCenterProcessCards()
						that.$message.success(response.info)

					} else {
						that.$message.error(response.info)
					}
				})

			},

			//委外出
			async wOuntSubmit() {
				var response = await this.$httpRequest({
					url: `MES/MESPostingZP/WOutProcessCard/${this.currentClickSingleProcessCardModel.id}?
					wOutOrInQty=${this.currentClickSingleProcessCardModel.resultcount}&
					description=${this.currentClickSingleProcessCardModel.description2}&
					type=40`,
					method: 'get'
				})

				if (response.status == 1) {
					this.wOuntDialog = false
					this.$message.success(response.info)
					this.getWorkCenterProcessCards()
				} else {
					this.$message.error(response.info)
				}
				// processCardStatus
				// currentClickSingleProcessCardModel	
			},
			//退料
			async backMaterialSubmit() {
				var check = this.WaitCreateMaterialDataList.filter(r => r.check == true)
				if (check.length <= 0) {
					this.$message.error('请选中需要退料的项')
					return
				}
				var response = await this.$httpRequest({
					url: `MES/MESPostingZP/AddBackOrder`,
					method: 'post',
					data: {
						childrencode: this.currentClickSingleProcessCardModel.childrenOrder.code,
						childrenid: this.currentClickSingleProcessCardModel.childrenorderid,
						backtype: this.selectBackMaterialType,
						requestList: this.WaitCreateMaterialDataList.filter(r => r.check == true)
					}
				})

				if (response.status == 1) {
					this.$message.success(response.info)
					this.cancel()
				} else {
					this.$message.error(response.info)
				}
			},
			//开始过账
			async operationStartOrStopOrEnd(card, status) {
				//暂停或结束 ：需要打开对话框
				if (status == 10 || status == 60) {
					this.postingDialog = true
				} else {
					var response = await this.$httpRequest({
						url: `MES/MESPostingZP/ProcessPosting?
						workcenterid=${this.workCenterModel.id}&
						cardId=${card.id}`,
						method: 'get'
					})

					if (response.status == 1) {
						this.$message.success(`工单号:${card.childrenOrder.code}已开始过账！`)
						this.getWorkCenterProcessCards()
						this.loadSingleProcessCard()
					}
				}
			},
			//过账对话框 录入数量
			async postingSubmit() {
				var status = null
				if (this.currentClickSingleProcessCardModel.isOver) {
					//完工（待入库）
					status = 60
				} else {
					//暂停
					status = 10
				}
				var response = await this.$httpRequest({
					url: `MES/MESPostingZP/ProcessPosting?
					workcenterid=${this.workCenterModel.id}&
					compltecount=${this.currentClickSingleProcessCardModel.tempOverCount}&
					status=${status}&
					cardId=${this.currentClickSingleProcessCardModel.id}`,
					method: 'get'
				})

				if (response.status == 1) {
					this.postingDialog = false
					this.$message.success(`工单号:${this.currentClickSingleProcessCardModel.childrenOrder.code}已报工成功！`)
					this.getWorkCenterProcessCards()
					this.loadSingleProcessCard()
				}

			},
			//流程卡展开
			expandedSingleProcessCardEvent(item) {
				if (item.value)
					this.loadProcessCardpostbillList(item.item)
			},
			//加载流程卡操控明细（过账明细）
			async loadProcessCardpostbillList(item) {
				var processCardId = item.id
				var response = await this.loadPostBillOrWorkHourOrMaterialList(
					`MES/MESPostingZP/GetProcessCardPostBillList?processCardId=${processCardId}`)

				if (!response)
					return

				item.processCardpostbillList = response.data.data
				this.processCardpostbillHeaderList = response.data.headers
			},

			async loadPostBillOrWorkHourOrMaterialList(url) {
				var response = await this.$httpRequest({
					url: url,
					method: 'get'
				})

				if (response.status != 1) {
					this.$message.error('加载数据失败')
				}
				return response
			},
			//扫码枪扫码后调用此方法过账
			handleBarcode(barcodeMap) {
				if (barcodeMap != null) {
					this.value = barcodeMap;
					this.postbillModel.showThisFlag = true
					this.postbillModel.workCenterId = this.workCenterModel.id
					this.postbillModel.processCardCode = this.getParameter(this.value, "processcardcode")
					this.postbillModel.areatype = this.workCenterModel.station.areatype
					this.postbillModel.controllerName = 'MESPostingZP'
				}
			},
			getParameter(url, name) {
				// postbill-manufacturing/processcardcode=lck000139
				var splits = url.toUpperCase().split('/');
				var allKeyValues = splits[splits.length - 1].split('&');
				for (var i = 0; i < allKeyValues.length; i++) {
					var singleKeyValue = allKeyValues[i].split('=')
					if (singleKeyValue[0] == name.toUpperCase()) {
						return singleKeyValue[1].toUpperCase()
					}
				}
				return '';
			},
			//模拟扫码过账
			async postBill() {
				this.postbillModel.showThisFlag = true
				this.postbillModel.workCenterId = this.workCenterModel.id
				this.postbillModel.processCardCode = this.tempProcessCardCode
				this.postbillModel.areatype = this.workCenterModel.station.areatype
				this.postbillModel.controllerName = 'MESPostingZP'
			},
			//扫码完成后回调此方法
			callBackLoadProcessCards() {
				this.loadSingleProcessCard()
				this.getWorkCenterProcessCards()

			},
			//弹出为外出检验对话框

			openOutsourcingDetailDialog(item) {
				this.checkInfo.cardModel = item
				this.checkInfo.assemblyCheckEditDialog = true
			},
			//弹出异常录入对话框
			openExceptionDialog(item) {
				this.activeAndonDialogModel.andonOperationDialog = true
				this.activeAndonDialogModel.childrenid = item.childrenorderid
				this.activeAndonDialogModel.controllerName = 'MESPostingZP'
		
			},
			loadMaterialHeaderList() {
				this.MaterialRequestOrderHeader = [

					{
						text: '选项',
						value: 'check'
					},
					{
						text: '退料数量',
						value: 'needqty'
					},
					{
						text: '备注',
						value: 'description'
					},
					{
						text: "物料代码",
						value: "materialcode"
					},
					{
						text: "物料名称",
						value: "materialname"
					},
					{
						text: "物料规格",
						value: "materialspecification"
					},
					{
						text: "物料型号",
						value: "materialmodel"
					},
					{
						text: "单位",
						value: "unitname"
					},
					{
						text: "库存数量",
						value: "storgeqty"
					},
					{
						text: "仓库",
						value: "storagename"
					}
				]
			},
		}

	}
</script>

<style>
</style>
